import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    // 当前导航的最后一次点击
    index: 0,
    Authorization: localStorage.getItem("Authorization")
      ? localStorage.getItem("Authorization")
      : "",
    ID: localStorage.getItem("ID") ? localStorage.getItem("ID") : "",
    socketID: "",
    // 保存用户的信息
    userinfo: {
      name: this.Authorization, //当前登陆的用户名
      socket: this.socketID, //当前用户的socketID
      img: "",    //头像
      userList: [], // 好友列表
      chatGroupList: [], // 群聊列表
      uninfonumber : "",  //当前有多少未读消息
      sendFriend: "", // 当前正在聊天好友的用户socketId
      sendChatGroup: "", // 当前正在聊天的群聊的roomId
      messageJson: {}, // 好友消息列表
      huxiangdans : "",   //互相关注
      flows : "",    //关注
      fans : ""      //粉丝
    },
  },
  mutations: {
    setuserList(state,data){
      data.color = "#DC143C"
      state.userinfo.userList.push(data)
      console.log(state.userinfo.userList,"--------")
    },
    setcolor(state,id){
      // let data = state.userinfo.userList
      for(let i=0;i<state.userinfo.userList.length;i++){
        if(state.userinfo.userList[i].from === id){
          state.userinfo.userList[i].color = "#00FF7F"
        }
      }
    },
    // 修改导航
    setindex(state, index) {
      state.index = index;
    },
    // 修改token，并将token存入localStorage
    changeLogin(state, user) {
      state.Authorization = user.Authorization;
      localStorage.setItem("Authorization", user.Authorization);
      localStorage.setItem("ID", user.id);
    },
    // 修改socketID
    setsocketID(state, socketID) {
      state.socketID = socketID;
    },
  },
  actions: {},
  modules: {},
});
